define(["jquery"],function(){
	return function(own,name){
		$("#" + name).hover(function(){
			$(this).css({"box-shadow":"0px 0px 8px #ccc"})
		},function(){
			$(this).css({"box-shadow":"none"})
		})
		var imported_li = document.getElementsByClassName(name + "_li");
		var now = 0;
		for(var i = 0; i < imported_li.length; i++){
			var li = imported_li[i];
			li.index = i;
			li.onmouseover = function(){
				for(var j = 0; j < imported_li.length; j++){
					imported_li[j].children[0].className = ""; 
				}
				now = this.index;
				load();
			}
		}
		function load(){
			var url = "json/" + name + ".json";
			own.ajaxGet(url,callback);
			function callback(mag){
				var arr = JSON.parse(mag);
				var l = arr[now].length;
				var str = "";
				for(var i = 0; i < l; i++){
					str += `<ol>
								<div class="${name}_div">
									<li>
										<img src="images/list/${arr[now][i].src}">
										<p>${arr[now][i].name}</p>
										<p class="${name}_price">${arr[now][i].price}</p>
										<p class="pat_cx"><a href="javascript:">立即查询</a><span class="zchc"></span></p>
									</li>
								<div>
							</ol>`;
				}
				var imported_list = document.getElementsByClassName(name + "_right_bom")[0];
				imported_list.innerHTML = str;
				imported_li[now].children[0].className = name + "_hover";
				$("." + name + "_right_bom").children("ol").children("." + name + "_div").hover(function(){
					$(this).css({"z-index":"10","box-shadow":"-10px 0px 2px #eee"}).stop().animate({
						"height" : "300",
						"top" : "-5"
					},200)
					$(this).children("li").css({"z-index":"10","box-shadow":"10px 0px 2px #eee"})
				},function(){
					$(this).css({"box-shadow":"none"}).stop().animate({
						"height" : "242",
						"top" : "0"
					},200,function(){
						$(this).css({"z-index":"1"});
						$(this).children("li").css({"z-index":"1"});
					});
					$(this).children("li").css({"box-shadow":"none"});
				})
				$("."+name+"_right_bom").children("ol").children("."+name+"_div").on("click",function(){
					var src = this.children[0].children[0].src;
					own.setCookie("xq",src);
					location.href = "detail.html";
				})
				$(".pat_cx").hover(function(){
					var i = 0;
					var timer = setInterval(function(){
						i += 2;
						if(i === 254){
							clearInterval(timer);
						}else{
							var rgb = "rgb("+i+","+i+","+i+")";
							$(".pat_cx").children("a").css({"color":rgb});
						}
					},1)
					$(this).children("span").stop().animate({"width":"120"},500);
				},function(){
					var i = 254;
					var timer = setInterval(function(){
						i -= 2;
						if(i === 0){
							clearInterval(timer);
						}else{
							var rgb = "rgb("+i+","+i+","+i+")";
							$(".pat_cx").children("a").css({"color":rgb});
						}
					},1)
					$(this).children("span").stop().animate({"width":"0"},500);
				})
			}
		}
		load();
	}
})
